﻿using Persons;

namespace PersonClient
{
    public class PClient
    {
        readonly PConnection _connection = new PConnection();

        public PClient()
        {
            _connection = new PConnection();
        }

        private bool AddHost(string hostName, int port)
        {
            return _connection.AddHost(hostName, port) > 0;
        }

        public bool Login(string hostName, int port)
        {
            if (AddHost(hostName, port))
            {
                _connection.Connect();
            }
            return _connection.Connected;
        }
        
        public bool Send(Person person)
        {
            return _connection.Connected && _connection.Send(person);
        }

        public bool Logout()
        {
            if (_connection.Connected)
            {
                _connection.Disconnect();
            }
            return _connection.Connected;
        }
    }
}
